package com.chenjun.common.util.crypto;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;

public class MDUtils {

	public static String enMD2(String str) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("MD2");
		byte[] digestBytes = md.digest(str.getBytes());
		// 转换为16进制
		char[] encodeHex = Hex.encodeHex(digestBytes);
		String enStr = new String(encodeHex);
		return enStr;
	}

	public static String enMD5(String str){
		MessageDigest md;
		try {
			md = MessageDigest.getInstance("MD5");
			byte[] digestBytes = md.digest(str.getBytes());
			// 转换为16进制
			char[] encodeHex = Hex.encodeHex(digestBytes);
			String enStr = new String(encodeHex);
			return enStr;
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return str;
	}
}
